package com.base.cn.platform.os.controller.user.count;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.entity.user.count.*;
import com.base.cn.platform.os.service.user.loginLog.CusUserLoginLogBiz;
import com.base.cn.platform.os.service.user.user.CusUserBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户统计Controller接口
 *
 * @author s.li
 * @create 2018-08-23-17:50
 */
@RestController
@RequestMapping("/manage/user")
public class UserCountController extends BaseController {

    @Autowired
    private CusUserBiz cusUserBiz;
    @Autowired
    private CusUserLoginLogBiz cusUserLoginLogBiz;


    /**
     * 查询用户数量
     * @return
     */
    @RequestMapping("/findUserCount")
    public Map<String,Integer> findUserCount(){
        BigDecimal sumUserNum = cusUserBiz.count(" 1=1 and status=1 ");
        BigDecimal buyUserNum = cusUserBiz.count(" buyCourse=2");
        Map<String,Integer> userNumMap = new HashMap<>();
        userNumMap.put("sumUserNum",sumUserNum.intValue());
        userNumMap.put("buyUserNum",buyUserNum.intValue());
        return userNumMap;
    }

    /**
     * 查询某一天平台用户24小时内每个小时的注册量
     * @param dateTime 查询的时间
     * @return UserRegDayNum
     */
    @RequestMapping("/queryUserRegDayTimeNum")
    public List<UserRegDayNum> queryUserRegDayTimeNum(@RequestParam("dateTime") String dateTime){
        return cusUserBiz.queryUserRegDayTimeNum(dateTime);
    }

    /**
     * 查询用户注册地理布局
     * @return 用户注册布局列表
     */
    @RequestMapping("/queryUserRegLayoutNum")
    public List<UserRegLayoutNum> queryUserRegLayoutNum(){
        List<UserRegLayoutNum> userRegLayoutNumList = cusUserBiz.queryUserRegLayoutNum();
        return userRegLayoutNumList;
    }

    /**
     * 用户登录设备统计量
     * @return 统计对象
     */
    @RequestMapping("/queryUserLoginDeviceNum")
    public UserLoginDeviceNum queryUserLoginDeviceNum(){
        return cusUserLoginLogBiz.queryUserLoginDeviceNum();
    }

    /**
     * 查询活跃用户数量
     * @return 数量
     */
    @RequestMapping("/queryActiveUserNum")
    public Integer queryActiveUserNum(){
        return cusUserLoginLogBiz.queryActiveUserNum();
    }

    /**
     * 查询注册对比数据统计数据
     * @return 统计数据对象
     */
    @RequestMapping("/queryRegFromUserNum")
    public UserRegFromNum queryRegFromUserNum(){
        return cusUserBiz.queryRegFromUserNum();
    }

    /**
     * 查询某一天平台用户24小时内每个小时的登录量
     * @param dateTime 时间
     * @return 统计数据列表
     */
    @RequestMapping("/queryUserLoginDayTimeNum")
    public List<UserLoginNum> queryUserLoginDayTimeNum(@RequestParam("dateTime") String dateTime){
        return cusUserLoginLogBiz.queryUserLoginDayTimeNum(dateTime);
    }

    /**
     * 查询平台用户某时间的注册量
     * @return
     */
    @RequestMapping("/queryUserDayTimeNum")
    public List<Map<String,Object>> queryUserDayTimeNum(@RequestBody Map<String,Object>  map){
        return cusUserBiz.queryUserDayTimeNum(map);
    }

    /**
     * 网站访问量曲线
     * @return 统计数据列表
     */
    @RequestMapping("/queryUserLoginTimeNum")
    public  List<Map<String,Object>> queryUserLoginTimeNum(@RequestBody Map<String,Object> map) {
        return cusUserLoginLogBiz.queryUserLoginTimeNum(map);
    }
        /**
         * 注册转化率
         * @return
         */
        @RequestMapping("/registerConversionRate")
        public String findRegisterConversionRate(@RequestBody Map map){
            return cusUserBiz.findRegisterConversionRate(map);
        }

        /**
         * 购买转化率
         * @return
         */
        @RequestMapping("/findOrderConversionRate")
        public String findOrderConversionRate(@RequestBody Map map){
            return cusUserBiz.findOrderConversionRate(map);
        }
        /**
         * 日活跃DUA
         * @return
         */
        @RequestMapping("/findActiveDUA")
        public String findActiveDUA(@RequestBody Map map){
            if(StringUtils.isEmpty(map.get("begTime"))&&StringUtils.isEmpty(map.get("endTime"))){
                map.put("begTime", DateUtils.format(new Date(),"yyyy-MM-dd"));
                map.put("endTime",DateUtils.format(new Date(),"yyyy-MM-dd"));
            }
            return cusUserBiz.findActiveDUA(map);
        }

        /**
         *  7日转化
         * @return
         */
        @RequestMapping("/findSevenDayConversion")
        public String findSevenDayConversion(){
            return cusUserBiz.findSevenDayConversion();
        }

        /**
         *  30日转化
         * @return
         */
        @RequestMapping("/findThirtyDayConversion")
        public  String findThirtyDayConversion(){
            return cusUserBiz.findThirtyDayConversion();
        }

}
